<?php
/**
 * @author 	 	 supfire@sohu.com
 * @copyright		 ourmy.com
 * @version		 1.0
 * @name 		 user.php
 * @todo 		 用户action
 * @final 		 2009-05-21
 */
define('IN_YCTOOL', true);//定义该文件合法性
if(isset($_GET['action']))
{
    if($_GET['action'] == 'datau')
    { 
        session_cache_limiter('private'); 
    }
}
require_once('config.php');
require_once(DIR_COMM . 'common.php');
$userid = $user->userinfo['userid'];
$email = $user->userinfo['email'];
$username = $user->userinfo['username'];
$enname = $user->userinfo['enname'];
$roles = $user->userinfo['roles'];
$mobile = $user->userinfo['mobile'];
//$user->onLine($user->userinfo['userid']);//是否在线 适用于全站
$uid = isset($_GET['uid']) ? $_GET['uid'] : 0;
!$uid && $uid = $userid;
$action	= isset($_GET['action']) ? $_GET['action'] : "";
if($uid != $userid)
{
    !$action && $action = "showdata";
}


//if($action)
//{
    $user->isLogin('', $uid);//没有登录 就跳转到登陆页面.
//}
//读取user的目录路径
$userpathusr = 'userdata/'.func::getFilePath($userid);
$userpath = $userpathusr . 'config/';
$actionPost	= isset($_POST['actionPost']) ? $_POST['actionPost'] : "";
    

$userorglisthome = db::getLeftJoin(DB_TABLEPRE . 'user_org', DB_TABLEPRE . 'web_org', 'a.orgid, b.orgname, b.type', 
    'a.orgid = b.orgid', "(a.type = 1 OR a.type = 5 OR a.type = 6) AND a.userid = $uid AND a.active = 1 ORDER BY CONVERT( b.orgname USING gbk ), a.uoid DESC");

if(!$userorglisthome)
{
	$userorglisthome = array();
}



//分别处理各个参数页面
switch ($action)
{
case 'rename':
    if ($actionPost == 'action')
    {
	$content = isset($_POST['content']) ? $_POST['content'] : "";
	$value   = isset($_POST['value']) ? $_POST['value'] : "";
	
	if(!$value)
	{
	    $text = '<span style="color:red">真实姓名不能为空！</span>';  
	}
	else
	{
	    if($user->modifyUserCount(1, $userid) > 1)
	    {
		$text = '<span style="color:red">您一年内只能修改 2 次 ，等下年才有机会修改，或者联系管理员！</span>';  
	    }
	    else
	    {
		if($user->modifyUser($value, $content, 1, $userid))
		{
		    $text = '<span style="color:red">真实姓名修改已提交，需１个工作日后审核通过生效！</span>';  
		}
	    }	
	}
    }  
    break;

case 'privacy':
    if($actionPost)
    {
    	$privacy			= isset($_POST['privacy']) ? $_POST['privacy'] : 0;
	//更新用户文件配置
	$arr_sub = array();
	$arr_sub["privacy"]		= $privacy;
	$arr[$userid] = $arr_sub;
	func::operateFile('variableprivacy', $arr, $userpath.'privacy', 'php', 2);
	$text = '提交成功';
    }
    //require_once($userpath.'privacy.php');
    break;

case 'app':

    if($actionPost)
    {
	$order = isset($_POST['order']) ? $_POST['order'] : 0;
    	$appid = isset($_POST['appid']) ? $_POST['appid'] : 0;
    	$appname = isset($_POST['appname']) ? $_POST['appname'] : '';
    	$appurl = isset($_POST['appurl']) ? $_POST['appurl'] : '';
    	$apporder = isset($_POST['apporder']) ? $_POST['apporder'] : 0;

	$arr_sub = array();
	for($i=0; $i<sizeof($order); $i++)
	{
	    $ipost = $order[$i];
	    $arr_sub[$ipost]["appid"] = $appid[$ipost];
	    $arr_sub[$ipost]["appname"] = $appname[$ipost];
	    $arr_sub[$ipost]["appurl"] = $appurl[$ipost];
	    $arr_sub[$ipost]["apporder"] = $apporder[$ipost];
	}

	if(!$order)
	{
	    $arr_sub = array();	    
	}
	//更新文件配置
	func::operateFile('variableapp', $arr_sub, $userpath.'app', 'php', 2);
	$text = '提交成功';
    }

    //获取所组件配置
    $path = DIR_DATA.'sys';
    $filename = "userapp.php";
    $filetype = "php";
    if (file_exists($path.'/'.$filename))
    {	
	$userapp = func::readFiles($path.'/'.$filename);
	$userapp = unserialize($userapp);
    }
    else
    {
	$userapp = array();  
    }

    if (file_exists($userpath.'app.php'))
    {
	require_once($userpath.'app.php');
    }
    else
    {
	$variableapp = array();
    }

    if($variableapp)
    {	
	foreach($variableapp as $key => $item)
	{
	    $appidarr[] = $item['appid'];
	}
    }
    break;

case 'psw'://修改密码
    /*
    //判断旧密码正确后再修改密码
    if ($actionPost == 'psw')
    {
	$psw_old = isset($_POST['psw_old']) ? $_POST['psw_old'] : "";
	$psw_new = isset($_POST['psw_new']) ? $_POST['psw_new'] : "";
	$psw_new2 = isset($_POST['psw_new2']) ? $_POST['psw_new2'] : "";

	if(!$psw_old || !$psw_new || !$psw_new2 || $psw_new != $psw_new2)
	{ $text = '密码不为空，或者两次密码输入不一致！- <a href="javascript:history.back()"> 返 回 </a>';}

	if(strlen($psw_new) < 4 || strlen($psw_new) > 100) 
	{$text = '密码要求在 4- 100 字符，请重新输入！ - <a href="javascript:history.back()"> 返 回 </a> ';}

	$psw_old=md5($psw_old);
	$psw_new=md5($psw_new);
	if (!$user->passwordTure($psw_old, $userid))
	{
	    $text = '旧密码错误！ - <a href="user.php?action=psw"> 返 回 </a> ';
	}
	else
	{
	    if($user->setPassword($psw_new, $userid))
	    {$text = '密码修改成功！- <a href="user.php?action=psw"> 返 回 </a> ';}
	    else{$text = '新密码和旧密码相同，密码改变！- <a href="user.php?action=psw"> 返 回 </a> ';}
	}

    }
     */
    break;
case 'setprivacy':

    $dataGet = isset($_GET['dataget']) ? $_GET['dataget'] : "info";

    include_once('config2.php');

    //添加或修改
   if($actionPost == 'add')
   {
	$order  = isset($_POST['order']) ? $_POST['order'] : 0;
	$pinfo  = isset($_POST['pinfo']) ? $_POST['pinfo'] : 0;
	$org  = isset($_POST['org']) ? $_POST['org'] : 0;

	for($i=0; $i<sizeof($order); $i++)
	{
	    $ipost = $order[$i];
	    $replacers['type'] = $ipost;
	    $replacers['userid'] = $userid;
	    $replacers['pinfo'] = $pinfo[$ipost];
	    db::replace(DB_TABLEPRE . 'user_privacy', $replacers, "userid = $userid AND type = $ipost");
	    
	    $orgrs = $org[$ipost];
	    if($pinfo[$ipost] == 1)
	    {
		unset($orgrs[0]);
		foreach($orgrs as $key => $v)
		{
		    $orgarr[$key]['type'] = $ipost;
		    $orgarr[$key]['userid'] = $userid;
		    $orgarr[$key]['orgid'] = $v;
		}
		db::deleteRs(DB_TABLEPRE . 'user_privacy_org', "userid = $userid AND type = $ipost");
		db::insertLot(DB_TABLEPRE . 'user_privacy_org', $orgarr);
	    }
	}
	func::alertMsg('修改成功');
   }
   $rslist = db::getLeftJoin(DB_TABLEPRE . 'user_privacy', DB_TABLEPRE . 'user_privacy_org', 
       'a.privacyid, a.userid, a.type, b.orgid, a.pinfo', 
       'a.type = b.type AND a.userid = b.userid', 
       "a.userid = $userid ORDER BY a.privacyid DESC");

    if(!$rslist)
    {
	$rslist = array(0=>'');
	
    }
    foreach($rslist as $key => $v)
    {
	$id = $v['type'];
	$rs[$id] = $v['pinfo'];
	$rsorg[$id][] = $v['orgid'];
    }

   // $userorglist = db::getLeftJoin(DB_TABLEPRE . 'user_org', DB_TABLEPRE . 'web_org', 'a.orgid, b.orgname', 
    //	'a.orgid = b.orgid', "(a.type = 1 OR a.type = 5 a.type = 6) AND a.userid = $userid AND a.active = 1 ORDER BY a.uoid DESC");
    $userorglist = $userorglisthome;

    if(!$userorglist)
    {
	$userorglist = array();
    }

    break;

case 'comment':
    $menu = 0;//导航: 0 为首页。


	//隐私 begin
	$fisok = 1;
	$fistype = 20;//类型 好友21 ，留言 20
	//if($userid != $uid)
	//{
	    $pinfo = db::getOne( DB_TABLEPRE . 'user_privacy', 'pinfo',  "userid = $uid AND type = $fistype");

	    if($pinfo == 1)
            {
	        $fisok = 0;
		//网络
		$rsorg = db::getCol( DB_TABLEPRE . 'user_org', 'orgid',  "userid = $uid ");
		$rsorg = implode(',', $rsorg);
                $rsporg = db::getAll( DB_TABLEPRE . 'user_privacy_org', 'orgid, userid, type',  "orgid IN ($rsorg) AND userid = $uid");

		if(!$rsporg)
		{
		    $rsporg = array();
		}

                $userorglisth = db::getLeftJoin(DB_TABLEPRE . 'user_org', DB_TABLEPRE . 'web_org', 'a.orgid, b.orgname, b.type', 
                    'a.orgid = b.orgid', "(a.type = 1 OR a.type = 5 OR a.type = 6) AND a.userid = $userid
                    AND a.active = 1 ORDER BY CONVERT( b.orgname USING gbk ), a.uoid DESC");

                if(!$userorglisth)
                {
                     $userorglisth = array();
                }

		//获取好友列表 begin
		$uid_path = 'userdata/'.func::getFilePath($uid);
		$arr_all_friend = array();
		if (file_exists($uid_path.'myfriend.php'))
		{
		    require($uid_path.'myfriend.php');
		}
		$friendid = array();
		if(array_unique($arr_all_friend))
		{
		    foreach ($arr_all_friend as $item)
		    {
			$friendid[] = $item['friendid'];
		    }
                }

		//获取好友列表 end
		if(in_array($userid, $friendid))
		{
		    $fisok = 1;
                }

                if($rsporg)
                {
       		    foreach($rsporg as $value)
		    {
			if($value['type'] == $fistype)
                        {
       		            foreach($userorglisth as $v)
                            {
                                if($value['orgid'] == $v['orgid'])
                                {
                                    $fisok = 1;
                                }
                            }
			}
                    }
                }
	    }
	    elseif($pinfo == 2 && $userid != $uid)
	    {
		$fisok = 0;
            }
            elseif($pinfo == 3)
            {
                $fisok = 0;
            }
            $fisokm = $fisok;

	//}
	//!$fisok && $data = array();  
	//隐私 end

    break;
case 'network':
    $menu = 0;//导航: 0 为首页。

    break;
case 'networkview':
    break;   
case 'netact':
    break;    

case 'links':
    include_once ('userlinks.php');
    break;
case 'act':
    $menu = 0;//导航: 0 为首页。
    break;
case 'dbagencies':
    break;

case 'datag':

    break;
case 'want':

    if ($actionPost == 'action')
    {
	$want = isset($_POST['want']) ? $_POST['want'] : "";
        $want = func::trChar($want);

	if(strlen($want) > 150)
	{
	    func::alertMsg('不能大于50个汉字');
	}

	$user->setWant($want, $userid);
	$arr_sub = array();
	$arr_sub["want"]		= $want;
	$arr_sub["time"]		= time();
	$arr[$userid] = $arr_sub;
	func::operateFile('variablewant', $arr, $userpath.'want', 'php', 2);
	$text = '修改成功！';

        db::insertRs(DB_TABLEPRE . 'msg_action','userid, 
                    friendid, type, message, addtime, note', "$userid, 0, 0, '修改了签名 $want', ". time() .", ''");

	//func::alertMsg('修改成功！');

    }
    if(file_exists($userpath.'want.php'))
    {
        require_once($userpath.'want.php');
    }	
    break;
case 'data'://设置 
    $dataGet = isset($_GET['dataget']) ? $_GET['dataget'] : "b";
    if($actionPost)
    {
        if($dataGet == 'cc')
        {
            $ccemail = isset($_POST['ccemail']) ? $_POST['ccemail'] : 0;
            $arr_sub = array();
            $arr_sub["ccemail"]		= $ccemail;
            $arr_sub["time"]		= time();
            $arr[$userid] = $arr_sub;
            func::operateFile('variableccemail', $arr, $userpath.'ccemail', 'php', 2);
            db::updateRs(DB_TABLEPRE . 'user_basic', 'ccemail = '.$ccemail, 'userid = '.$userid);
            db::updateRs(DB_TABLEPRE . 'msg_thread', 'ccemail = '.$ccemail, 'touid like \'%'.$userid.',%\' AND sendok = 0');
            func::alertMsg('修改成功！');
        }
        unset($_POST['faceok']);
        $rslistk = $user->getUserBasicMember($userid);
        $rslistk = Func::adsslashesArray($rslistk[0]);

        if($_POST['sex'] == 1)
        {
            $sexname = '男';
        }elseif($_POST['sex'] == 2)
        {
            $sexname = '女';
        }
        ($_POST['sex'] && $rslistk['sex'] != $_POST['sex']) && $msginsertAction .= "($userid, 0, 4, '性别为 $sexname', ".time().", ''),";

	($_POST['province'] && $rslistk['province'] != $_POST['province']) && $msginsertAction .= "($userid, 0, 4, '地区网络为 ".$_POST['province'] ."', ".time().", ''),";
        //($_POST['city'] && $rslistk['city'] != $_POST['city']) && $msginsertAction .= "($userid, 0, 4, '城市网络', ".time().", ''),";

        ($_POST['birth_year'] && $rslistk['birth_year'] != $_POST['birth_year']) && $msginsertAction .= "($userid, 0, 4, '出生年为 ".$_POST['birth_year'] ."年', ".time().", '') ,";
        ($_POST['birth_month'] && $rslistk['birth_month'] != $_POST['birth_month']) && $msginsertAction .= "($userid, 0, 4, '出生月为 " .$_POST['birth_month'] ."月', ".time().", '') ,";
        ($_POST['birth_day'] && $rslistk['birth_day'] != $_POST['birth_day']) && $msginsertAction .= "($userid, 0, 4, '出生日为 ".$_POST['birth_day'] ."日', ".time().", '') ,";
	($_POST['care'] && $rslistk['care'] != $_POST['care']) && $msginsertAction .= "($userid, 0, 4, '关心领域为 ".$_POST['care'] ."', ".time().", ''),";
	($_POST['edu'] && $rslistk['edu'] != $_POST['edu']) && $msginsertAction .= "($userid, 0, 4, '教育经历为 ".$_POST['edu'] ."', ".time().", ''),";
	($_POST['work'] && $rslistk['work'] != $_POST['work']) && $msginsertAction .= "($userid, 0, 4, '工作经历为 ".$_POST['work'] ."', ".time().", ''),";
        ($_POST['link'] && $rslistk['link'] != $_POST['link']) && $msginsertAction .= "($userid, 0, 4, '联系方式为 ".$_POST['link'] ."', ".time().", ''),";

        if(
            ($_POST['agencyName'] && $rslistk['agencyName'] != $_POST['agencyName']) ||
            ($_POST['agencyAdd'] && $rslistk['agencyAdd'] != $_POST['agencyAdd']) ||
            ($_POST['agencyFunctions'] && $rslistk['agencyFunctions'] != $_POST['agencyFunctions']) ||
            ($_POST['agencyNumber'] && $rslistk['agencyNumber'] != $_POST['agencyNumber']) ||
            ($_POST['agencyTel'] && $rslistk['agencyTel'] != $_POST['agencyTel']) ||
            ($_POST['agencyNature'] && $rslistk['agencyNature'] != $_POST['agencyNature']) 
        )
        {
            $msginsertAction .= "($userid, 0, 4, '代表机构信息', ".time().", ''),";
        }
	($_POST['tel'] && $rslistk['tel'] != $_POST['tel']) && $msginsertAction .= "($userid, 0, 4, '联系电话为 ".$_POST['tel'] ."', ".time().", ''),";
        ($_POST['address'] && $rslistk['address'] != $_POST['address']) && $msginsertAction .= "($userid, 0, 4, '通讯地址为 ".$_POST['address'] ."', ".time().", ''),";

	($_POST['field1'] && $rslistk['field1'] != $_POST['field1']) && $msginsertAction .= "($userid, 0, 4, '兴趣和特长为 ".$_POST['field1'] ."', ".time().", ''),";
	($_POST['field2'] && $rslistk['field2'] != $_POST['field2']) && $msginsertAction .= "($userid, 0, 4, '教育背景为 ".$_POST['field2'] ."', ".time().", ''),";
	($_POST['field3'] && $rslistk['field3'] != $_POST['field3']) && $msginsertAction .= "($userid, 0, 4, '职业历史为 ".$_POST['field3'] ."', ".time().", ''),";
	($_POST['field4'] && $rslistk['field4'] != $_POST['field4']) && $msginsertAction .= "($userid, 0, 4, '职业有关特长和技能为 ".$_POST['field4'] ."', ".time().", ''),";
	($_POST['field5'] && $rslistk['field5'] != $_POST['field5']) && $msginsertAction .= "($userid, 0, 4, '喜欢的书为 ".$_POST['field5'] ."', ".time().", ''),";
	($_POST['field6'] && $rslistk['field6'] != $_POST['field6']) && $msginsertAction .= "($userid, 0, 4, '喜欢的音乐为 ".$_POST['field6'] ."', ".time().", ''),";
	($_POST['field7'] && $rslistk['field7'] != $_POST['field7']) && $msginsertAction .= "($userid, 0, 4, '喜欢的电影为 ".$_POST['field7'] ."', ".time().", ''),";
	($_POST['field8'] && $rslistk['field8'] != $_POST['field8']) && $msginsertAction .= "($userid, 0, 4, '喜欢的引言为 ".$_POST['field8'] ."', ".time().", ''),";
        
        ($_POST['field9'] && $rslistk['field9'] != $_POST['field9']) && $msginsertAction .= "($userid, 0, 4, '关于我为 ".$_POST['field9'] ."', ".time().", ''),";

        $msginsertAction = substr($msginsertAction, 0, -1);
        
	$msginsertAction && msg::insertAction($msginsertAction);
    }

    
    $userface = $userpath.'face';
    if (file_exists($userface.'0.jpg'))
    {
	$userfacejpg = $userface.'0.jpg';
    }
    else
    {
	$userfacejpg = 'common/img/nopic.gif';
    }

    $delorg = isset($_GET['delorg']) ? $_GET['delorg'] : "";
    if($delorg == 'delorg')
    {
	$orgid = $_GET['orgid'];
	$type = $_GET['type'];
	if($orgid)
	{
	    $isOk = db::deleteRs(DB_TABLEPRE . 'user_org', 
                'orgid = '. $orgid . ' AND userid = '. $userid . ' AND type = '.$type );
            if($isOk)
            {
                $oneorgid = $orgid;
                $oneweb = db::getOne(DB_TABLEPRE . 'web_org', 'orgname', "orgid = $oneorgid");
                $message = '离开了“<a href="user.php?action=networkview&orgid='.$oneorgid .'">'. $oneweb .'</a>”网络';
                db::insertRs(DB_TABLEPRE . 'msg_action','userid, 
                                friendid, type, message, addtime, note', "$userid, 0, 0, '$message', ". time() .", ''");
            }
            

            //func::alertMsg('删除成功！');
	}
    }

    if($actionPost == 'add')
    {
	is_numeric($_POST['sex']) ? $_POST['sex'] : $_POST['sex'] = 0;
	$_POST['interesse'] && $_POST['interesse'] = ',' . implode(',', $_POST['interesse']) . ',';
	//$updaters = $_POST;

	//unset($updaters['actionPost']);
	//$updaters['modifytime'] = NOWTIME;

	$upuser['sex'] = $_POST['sex'];
	$upuser['birth_year'] = $_POST['birth_year'];
	$upuser['birth_month'] = $_POST['birth_month'];
	$upuser['birth_day'] = $_POST['birth_day'];
	$upuser['province'] = $_POST['province'];
	$upuser['city'] = $_POST['city'];
	$upuser['tel'] = $_POST['tel'];
	$upuser['address'] = $_POST['address'];
	$upuser['modifytime'] = NOWTIME;

	//更新用户信息数据库
	$user->updateU($userid, $upuser);
        //添加城市网络
        $orgidprovince = db::getOne(DB_TABLEPRE . 'web_org', 'orgid', 'orgname = "'.$_POST['province'].'"');
        if($orgidprovince)
        {
                $insertrs["orgid"] = $orgidprovince;
                $insertrs["userid"] = $userid;
                $insertrs["type"] = 6;
                $insertrs["useremail"] = '';
                $insertrs["active"] = 1;
                $insertrs["code"] = '';
                db::replace(DB_TABLEPRE . 'user_org', 
                    $insertrs, 'userid = '. $userid . ' AND type = 6' );
                unset($insertrs);
        }
        $emailtext = '资料修改成功';
        func::alertMsg($emailtext, 'user.php?action=data');
    }
    if($actionPost == 'addorg')
    {
         //添加机构校友网络
	$type = $_POST['type'];
	$org = $_POST['org'];
	$useremail = $_POST['useremail'];
	if($org)
        {
	    foreach ($org as $key => $value)
	    {
		if($value)
		{
                        $useremailone = db::getOne(DB_TABLEPRE . 'user_org', 'useremail', 
                            'orgid = '.$value. '
                                AND userid = '. $userid . ' AND active = 1 ');
                        if($useremailone)
                        {
                            func::alertMsg('您已经添加了该网络', 'user.php?action=data');
                        }
                }
            }

	    require_once(DIR_COMM . 'sendmail.php');
	    foreach ($org as $key => $value)
	    {
		if($value)
		{
		    if($useremail[$key])
		    {
                        $useremailone = db::getOne(DB_TABLEPRE . 'user_org', 'useremail', 
                            'orgid = '.$value. '
                            AND userid = '. $userid . ' 
                            AND active = 1 AND type = '. $type[$key]);	

			if(func::isEmail($useremail[$key]))
			{
			    $useremailtmp = substr( strrchr($useremail[$key], '@'), 1 );
			    $rsone = db::getOne(DB_TABLEPRE . 'web_org', 'detail', 'orgid = '.$value);
			    $rsone = explode(",", $rsone);

                            if(in_array($useremailtmp, $rsone))
			    {
				if(!$useremailone)
				{
				    $code = mt_rand() . 't';
                                    $detailhtml = '<META http-equiv=Content-Type content="text/html; charset='.Email_CHARSET.'"></HEAD>
                                        <br /><br />请使用本邮件中的链接确认您要加入的童心网机构网络。
                                        <a href="http://'.YCTOOL_HTTPHOST.'/useremailurl.php?userid='.
                                        $userid.'&code='.$code.'&useremail='.$useremail[$key].'"
					target="_blank">http://'.YCTOOL_HTTPHOST.'/useremailurl.php?userid='.
                                        $userid.'&code='.$code.'&useremail='.$useremail[$key].'</a><br /><br />
					';
				    $emailList .= $useremail[$key].'， ';
				    $insertrs["orgid"] = $value;
				    $insertrs["userid"] = $userid;
				    $insertrs["type"] = $type[$key];
				    $insertrs["useremail"] = $useremail[$key];
				    $insertrs["active"] = 0;
				    $insertrs["code"] = $code;

				    db::replace(DB_TABLEPRE . 'user_org', 
                                        $insertrs, 'orgid = '. $value . '
                                        AND userid = '. $userid . ' 
                                        AND type = '. $type[$key] );
                                    SendMail($useremail[$key], '确认您要加入的童心网机构网络', $detailhtml);
				    unset($insertrs);
				}
			    }
			    else
			    {
				$isEmail .= $useremail[$key].'， ';
			    }
			}
			else
			{
			    $noEmail .= $useremail[$key].'， ';
			
			}
		    }
		}
	    }
	}
	
	$emailList && $emailtext .= '确认邮件已被发送至您的电子邮箱 '.$emailList.'请查看邮件并激活网络，谢谢！ ';
	$isEmail && $emailtext .=  ' '.$isEmail.'与所在学校或机构邮箱后缀不符  ';
        $noEmail && $emailtext .=  ''.$noEmail.'格式有误 ';
        !$emailtext && $emailtext = '请选择网络名称';
       	$emailtext && func::alertMsg($emailtext, 'user.php?action=data');
    }

    if($actionPost == 'o')
    {
	$upuser['type'] = 1;
	$upuser['orgname'] = trim($_POST['orgname']);
	$upuser['detail'] = trim($_POST['detail']);
	$upuser['linker'] = $userid;
	$upuser['linkemail'] = $username;
	$upuser['active'] = -9;
	$upuser['addtime'] = NOWTIME;
	if(!func::isEmail($upuser['detail']))
	{
	    func::alertMsg($upuser['detail'].'邮箱格式不对');
	}

	//$emailone = db::getOne(DB_TABLEPRE . 'web_org', 'orgid', 
	  //   'orgname = "'.$upuser['orgname']. '" AND type = 1 ');
	//if($emailone)
	//{
	 //   func::alertMsg($upuser['orgname'].'已经存在');
	//}
	//else
	//{
	    db::insert(DB_TABLEPRE . 'web_org', $upuser);
	    func::alertMsg('提交成功');
//	}

    }
    if($actionPost == 'u')
    {
        $updaters = $_POST;

	unset($updaters['actionPost']);
	unset($updaters['face2']);
	$updaters['modifytime2'] = NOWTIME;
	//更新用户信息数据库
	$user->updateMember($userid, $updaters);
        
        //$faceok = $_POST['faceok'];
       // if($faceok)
        //{
        
  	  //  $user->facetrue($userid, $userface.'.jpg');
	    //msg::insertAction("($userid, 0, 3, '<div class=l50_s>
	//	<a href=\"user.php?uid=".$userid."\"><IMG src=".$userface.".jpg height=56 width=56 border=0></a>
	//	</div>', ".time().", '')");      
        
        //}
        /*
	$img = $_FILES["face2"];
	if($img["size"])
	{
	    func::errorUploadImage($img,2000000);
	    func::imageIsResize($img["tmp_name"], 180, 180, $userface.'0.jpg');
	    func::imageIsResize($img["tmp_name"], 56, 56, $userface.'.jpg');

	}
        unset($img);
         */
	//func::showMsg('提交成功 <br />', '', 'user.php?action='.$action.'&dataget='.$dataGet);
    }
    if($actionPost == 'j')
    {
	$upuser = $_POST;
	unset($upuser['actionPost']);
	$upuser['modifytime'] = NOWTIME;
	//更新用户信息数据库
	$user->updateU($userid, $upuser);
	func::alertMsg('提交成功');

	//func::showMsg('提交成功<br />', '', 'user.php?action='.$action.'&dataget='.$dataGet);
    }

    //判断旧密码正确后再修改密码
    if ($actionPost == 'psw')
    {
	$email = isset($_POST['email']) ? $_POST['email'] : "";
	$psw_oldx = $psw_old = isset($_POST['psw_old']) ? $_POST['psw_old'] : "";
	$psw_new = isset($_POST['psw_new']) ? $_POST['psw_new'] : "";
	$psw_new2 = isset($_POST['psw_new2']) ? $_POST['psw_new2'] : "";
	$pwdAnswer = isset($_POST['pwdAnswer']) ? $_POST['pwdAnswer'] : "";
	$pwdAnswer2 = isset($_POST['pwdAnswer2']) ? $_POST['pwdAnswer2'] : "";

	$newpwdAnswer = isset($_POST['newpwdAnswer']) ? $_POST['newpwdAnswer'] : "";
	$newpwdAnswer2 = isset($_POST['newpwdAnswer2']) ? $_POST['newpwdAnswer2'] : "";
	$pwdQuestion = isset($_POST['pwdQuestion']) ? $_POST['pwdQuestion'] : "";
        $pwdQuestion2 = isset($_POST['pwdQuestion2']) ? $_POST['pwdQuestion2'] : "";

        $userid = $user->userinfo['userid'];

	//if($psw_new)
	//{
	    if(!$psw_old || !$psw_new || !$psw_new2 || $psw_new != $psw_new2)
            {
                func::alertMsg('请输入正确的不为空的新密码');
            }

	    if(strlen($psw_new) < 4 || strlen($psw_new) > 100) 
            {
                func::alertMsg('密码要求在 4- 100 字符，请重新输入！ ');
            }

            $psw_old = md5($psw_old);
            $psw_oldt = $_POST['old'];
            $psw_new = md5($psw_new);
            if ($psw_oldt == $psw_old)
            {
                    unset($upuser);
                    $upuser['userpass'] = $psw_new;

                    if($pwdQuestion || $pwdAnswer || $pwdQuestion2 || $pwdAnswer2)
                    {

                        //echo '<hr> 1 ' .
                            $oldpwdQuestion = $_POST['oldpwdQuestion'];
                        //echo '<hr> 2 ' . 
                            $md5pwdQuestion = md5($pwdQuestion);

                        //echo '<hr> 3 ' . 
                            $oldpwdQuestion2 = $_POST['oldpwdQuestion2'];
                        //echo '<hr> 4 ' . 
                            $md5pwdQuestion2 = md5($pwdQuestion2);

                        //echo '<hr> 5 ' . 
                            $oldpwdAnswer = $_POST['oldpwdAnswer'];
                        //echo '<hr> 6 ' . 
                            $md5pwdAnswer = md5($pwdAnswer);

                        //echo '<hr> 7 ' . 
                            $oldpwdAnswer2 = $_POST['oldpwdAnswer2'];
                        //echo '<hr> 8 ' . 
                            $md5pwdAnswer2 = md5($pwdAnswer2);
                        

                        if(
                            (
                                ($oldpwdQuestion == $md5pwdQuestion && $oldpwdAnswer == $md5pwdAnswer)
                                &&
                                ($oldpwdQuestion2 == $md5pwdQuestion2 && $oldpwdAnswer2 == $md5pwdAnswer2)
                            )
                            ||
                            (
                                ($oldpwdQuestion2 == $md5pwdQuestion && $oldpwdAnswer2 == $md5pwdAnswer)
                                &&
                                ($oldpwdQuestion == $md5pwdQuestion2 && $oldpwdAnswer == $md5pwdAnswer2)
                            )
                        )
                        {
                            $tempk = 0;   
                        }
                        else
                        {
                            func::alertMsg('您需要输入正确的密码信息 ');
                        }


                        $pwdQuestion && $upuser['pwdQuestion'] =  $pwdQuestion;
                        $newpwdAnswer && $upuser['pwdAnswer'] =  $newpwdAnswer;
                        $pwdQuestion2 && $upuser['pwdQuestion2'] =  $pwdQuestion2;
                        $newpwdAnswer2 && $upuser['pwdAnswer2'] =  $newpwdAnswer2;
                    }
                    db::update(DB_TABLEPRE . 'user_basic',   $upuser,   'userid = '.$userid);

                    if($pwdQuestion || $pwdAnswer || $pwdQuestion2 || $pwdAnswer2)
                    {
                        echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                        <style type="text/css">body{ background-color:#FFFFFF;}</style>
                        <body><script type=\'text/javascript\'>alert("密码和提示问题答案修改成功");document.location="user.php?action=data&dataget=psw";</script>';
                        exit;
                    }
                    else
                    {
                        echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                        <style type="text/css">body{ background-color:#FFFFFF;}</style>
                        <body><script type=\'text/javascript\'>alert("密码修改成功");document.location="user.php?action=data&dataget=psw";</script>';
                        exit;

                    }
             }       
            else
            {
                echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                    <style type="text/css">body{ background-color:#FFFFFF;}</style>
                    <body><script type=\'text/javascript\'>alert("您需要输入正确的密码信息");document.location="user.php?action=data&dataget=psw";</script>';
                exit;
            }
            unset($upuser);
            unset($_POST);
            unset($_GET);
	//}
/*
	if($pwdQuestion)
	{
	    $one = db::getOne(DB_TABLEPRE . 'user_basic', 'userid',
		"pwdAnswer = '$pwdAnswer' AND pwdQuestion = '$pwdQuestion' AND userid = $userid");
	    if( $one )
	    {
		$upuser["pwdAnswer"] = $newpwdAnswer;
		$user->updateU($userid, $upuser);
		$text .= '提示问题答案一修改成功！';

	    }
	    else
	    {
		$text .= '密码提示问题一或提示问题答案一错误！';

	    }
	}

	if($pwdQuestion2)
	{
	    $one = db::getOne(DB_TABLEPRE . 'user_basic', 'userid',
		"pwdAnswer2 = '$pwdAnswer2' AND pwdQuestion2 = '$pwdQuestion2' AND userid = $userid");
	    if( $one )
	    {
		$upuser["pwdAnswer2"] = $newpwdAnswer2;
		$user->updateU($userid, $upuser);
		$text .= '提示问题答案二修改成功！';
	    }
	    else
	    {
		$text .= '密码提示问题二与提示问题答案二错误！';
	    }
	}
	$text && func::alertMsg($text);
 
	$value = trim($email);
	if(!func::isEmail($value))
	{
	     $text = "E-mail地址格式不正确";
	}
	if(!$value)
	{
	    $text = 'Email不能为空！';  
	}
	else
	{
	    $emailold = db::getOne(DB_TABLEPRE . 'user_basic', 'email', "userid = '$userid'");
	    if($emailold != $value)
	    {
		if($user->getOneUser($value))
		{
		    $text = $value.'已经占用，您不能使用此邮箱';
		}
		else
		{
		    $arr_sub = array();
		    $arr_sub["findreemail"] = $value;
		    $arr[$userid] = $arr_sub;
		    func::operateFile('variablereemail', $arr, $userpath.'reemail', 'php', 2);

		    //save check code
		    $findpsw = mt_rand();
		    $arr_sub = array();
		    $arr_sub[$userid]["findpsw"] = $findpsw;
		    $arr_sub[$userid]["friendid"] = 0;
		    func::operateFile('variable', $arr_sub, $userpath.'findpsw', 'php', 2);
		    
		    require_once(DIR_COMM . 'sendmail.php');
		    $posttext = '
		    <HTML><HEAD>
		    <TITLE>Mail</TITLE>
		    <meta http-equiv="Content-Type" content="text/html; charset='.Email_CHARSET.'">
		    </HEAD>
		    <BODY bgColor=#FFFFFF topmargin=5
		    leftmargin=5 style="FONT-SIZE:9pt; FONT-FAMILY:宋体">
		    <div>
		    您修改了您的邮箱。需要激活才能完成修改操作，请使用此链接确认：<br>
		    <a href="http://'.CTDF_HTTPHOST.'/c.php?reemail='.$findpsw.'&email='.$value.'"
		    >http://'.CTDF_HTTPHOST.'/c.php?reemail='.$findpsw.'&email='.$value.'</a><br>
		    <br>
		    </div>
		    </BODY></HTML>';
		    $mailok = SendMail($value, CTDF_HTTPHOST.'修改Email确认', $posttext);
		    $user->modifyUserEmail($value, '用户修改邮箱', 2, $userid);
		    if($mailok)
		    {
			$text = '已经给您的 '.$value.' 发送确认邮件，需通过邮件确认后才能生效！';  
		    }		
		}
	    }
	}
	$text && func::alertMsg($text);
 */   }

    $rsuser = $rslist = $user->getUserBasicMember($userid);

    $rs = db::getAll(DB_TABLEPRE . 'web_org', '*', "(type = 1 OR type = 5) AND active <> -1 AND active > -9 ORDER BY CONVERT( orgname USING gbk ),  active DESC, orgid DESC");

    if(!$rs)
    {
	$orglist = array();
    }
    else
    {
 
	foreach ($rs as $i => $value)
	{
	    if($value['type'] == 1 || $value['type'] == 5 )
	    {
		$orglist[1][] = $value;
	    }
	    if($value['type'] == 5)
	    {
		$orglist[2][] = $value;
	    }
	}
    }

    $rs = db::getAll(DB_TABLEPRE . 'user_org', '*', "(type = 1 OR type = 5) AND userid = $userid AND active = 1 ORDER BY uoid DESC");
    if(!$rs)
    {
	$userorglist = array();
    }
    else
    {
	foreach ($rs as $i => $value)
	{
	    if($value['type'] == 1)
	    {
		$userorglist[1][] = $value;
	    }
	    elseif($value['type'] == 5)
	    {
		$userorglist[2][] = $value;
	    }
	}
    }
    //print_r($userorglist);

    unset($rs);
    break;

case 'face'://修改头像
    $dataGet = isset($_GET['dataget']) ? $_GET['dataget'] : "face";
    $userface = $userpath.'face';
    if($actionPost == 'upfile')
    {
	$img = $_FILES["face2"];
	if($img["size"])
	{
	    func::errorUploadImage($img,2000000);
	    func::imageIsResize($img["tmp_name"], 180, 180, $userface.'0.jpg');
	    func::imageIsResize($img["tmp_name"], 56, 56, $userface.'.jpg');
	    $user->facetrue($userid, $userface.'.jpg');
	    msg::insertAction("($userid, 0, 3, '<div class=l50_s>
		<a href=\"user.php?uid=".$userid."\"><IMG src=".$userface.".jpg height=56 width=56 border=0></a>
		</div>', ".time().", '')");
	}
	unset($img);
    }

    break;
case 'sendemail':
    $healthy = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    $yummy   = array('u', 'I', 'g', 'O', 'j', 'v', 'n', 'l', 'a','r');
    $c = ( 7 * ( 53 * ( $userid + 5 )  + 3 ) - 1 ) * 3 + 9;
    $c = str_replace($healthy, $yummy, $c);
    $regurl = 'a/?c='.$c;
    $type	= isset($_GET['type']) ? $_GET['type'] : 0;
    if($type == 1)
    {	
	if ($actionPost == 'action')
	{
	    //MSN
	    $msnusr = isset($_POST['msnusr']) ? $_POST['msnusr'] : "";
	    $msnpsw = isset($_POST['msnpsw']) ? $_POST['msnpsw'] : "";
	    require_once(DIR_COMM . 'email/msnone.class.php');
	    $msn = new msn;
	    $content = $msn->getmsnlist($msnusr, $msnpsw);
	    if (!$content)
	    {
		if($msn->geterrorcode() == 1)
		{
		    func::alertMsg("对不起，您的用户名或者密码错误！");
		}
	    }
	}
    }
    //CVS , VCF
    if($type == 2)
    {
	
	if ($actionPost == 'action')
	{
	    $img = $_FILES["email"];
	    if(!$img["size"])
	    {
		$text = '<span style="color:red">您的文件没有上传，请选择返回重新上传。</span>'; 
	    }
	    else
	    {
		$filename = $img["tmp_name"];
		unset($img);
		$handle = fopen($filename, "r");
		$content = fread($handle, filesize($filename));
		fclose($handle);
		mb_detect_encoding($content) != 'UTF-8' && $content = iconv("GB2312", "UTF-8", $content);

		preg_match_all("/[a-z0-9_\.\-]+@[a-z0-9\-]+\.[a-z]{2,6}/i", $content, $matches);
		if(($emails = array_unique($matches[0])) !=false) {
			$contacts = $emails;
		}
		unset($matches);
		$content = $contacts;
		!$content && $content = array();
		$content = array_unique($content);
	    }
	}
    }
    //if($type == 3)
    //{
	//链接邀请
    //}
    if($type == 4)
    {
	//Email邀请
	$content = isset($_POST['content']) ? $_POST['content'] : "";
	if ($content)
	{
            preg_match_all("/[a-z0-9_\.\-]+@[a-z0-9\.\-]+\.[a-z]{1,6}/i", $content, $matches);
		if(($emails = array_unique($matches[0])) !=false) {
			$contacts = $emails;
		}
		unset($matches);
	    $content = $contacts;
	    !$content && $content = array();
	    $content = array_unique($content);
	}
    }
    if($type == 5)
    {

	if ($actionPost == 'action')
	{

	if(!$_POST['account'] || !$_POST['passwd'] || !$_POST['postoffice']){
	    func::alertMsg('邮箱和密码不能为空，请返回重新输入');
	}
	//取得联系人 UTF8
	require_once(DIR_COMM . 'email/mailfactory.php');
	switch ($_POST['postoffice']) {
		case "126.com":
			$contact = new MailFactory(M126);
			break;
		case "sina.com":
			$contact = new MailFactory(MSINA);
			break;
		case "tom.com":
			$contact = new MailFactory(MTOM);
			break;
		case "gmail.com":
			$contact = new MailFactory(MGOOGLE);
			break;
		case "163.com":
			$contact = new MailFactory(M163);
			break;
		case "sohu.com":
			$_POST['account'] = $_POST['account'] . "@" . $_POST['postoffice'];
			$contact = new MailFactory(MSOHU);
			break;
		case "vip.sohu.com":
			$_POST['account'] = $_POST['account'] . "@" . $_POST['postoffice'];
			$contact = new MailFactory(MSOHU_VIP);
			break;
		case "yahoo.cn":
		case "yahoo.com":
		case "yahoo.com.cn":
			$_POST['account'] = $_POST['account'] . "@" . $_POST['postoffice'];
			$contact = new MailFactory(MYAHOO);
			break;
		default:
			func::showMsg('没有导入，请返回重新选择邮箱 点确定返回');
		
	}
	$contacts = $contact->getContactList($_POST['account'], $_POST['passwd']);

	if($contacts == 0) {func::showMsg('没有导入，可能是密码不对，请返回重新选择邮箱 点确定返回');}
	if(empty($contacts)) {func::showMsg('导入邮箱好友为空，可能是密码不对，请返回重新选择邮箱 点确定返回');}

	if($_POST['postoffice'] == "sina.com" || $_POST['postoffice'] == "sohu.com" || $_POST['postoffice'] == "vip.sohu.com" )
       	{
	    $contacts = array_flip($contacts);
	}
	//导入邮箱的通讯
	$content = $contacts;
	!$content && $content = array();
	$content = array_unique($content);
	}
	
    }

    //导入邮箱 加入通讯录，发送email。
    if($actionPost == 'action' && $content)
    {
	$content = str_replace(";", ",", $content);
	//取数据库中所有email列表
	$flist = $user->getEmailList($userid);

    	if ($content)
	{
	    !$flist && $flist = array();
    	    while (list($key, $value) = each($content))
    	    {
		if (!func::isEmail($value))
	    	{
		    $erroremail .= $value.",";
		}
		else
		{
		    if (!in_array($value, $flist))
		    {
			//写群插入sql语句
			$addEmail .= '('.$userid.',"'.$value.'"),';
		    }
		    $isMail .= $value.',';   
		}
	    }

    	    unset($value);
	    unset($content);
    	    $isMail = substr($isMail, 0, -1);//去掉末尾 “,”
	    $addEmail = substr($addEmail, 0, -1);
	    if($addEmail)
	    {
		// 所有好友一次性全部加入  
		$user->addEmailForUser($addEmail);
	    }
	}
	if(!$isMail)
	{
	    func::showMsg('<span style="color:red">没有有效的好友 Email</span> 点确定返回');
	}

	$id	    = $_GET['id'];
	$fromname   = $user->userinfo['username'];
	$_POST['username'] && $fromname = $_POST['username'];
	$frommail   = $user->userinfo['email'];
	$now1	    = date("Y").' 年 '.date("m").' 月 '.date("d").' 日 ';
	$face	    = $userpath.'face0';
	$detail	    = isset($_POST['detail']) ? $_POST['detail'] : "";
	$detail    = htmlspecialchars($detail);
	$detail    = str_replace(" ", "&nbsp;", $detail);
	$detail    = str_replace("\n", "<br />", $detail);
        $detail    = str_replace("\\", "", $detail);

	$detailhtml = '<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN>
<HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Language content=zh-cn>
<META http-equiv=Content-Type content="text/html; charset='.Email_CHARSET.'"></HEAD>
<style> .hmmessage P { margin:0px; padding:0px } body.hmmessage { FONT-SIZE: 9pt; FONT-FAMILY:Tahoma } </style>
</HEAD>
<BODY class="hmmessage">
<table width="100%" cellspacing="0" cellpadding="20" border="0"><tr><td bgcolor="#F7F7F7">
	<table width="600" cellspacing="0" cellpadding="0" border="0">
		<tr>
		<th bgcolor="#00bb00" align="left" style="padding:4px 20px;color:#fff;font-size:24px;font-weight:bold;line-height:150%;">
		  [ '.$fromname.' ]  
		</th>
		</tr>
	</table>
	<table width="600" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff" style="border:1px solid #ccc; border-top:none;">
		<tr>
			<td width="151" valign="top" align="center" style="padding:10px;font-family:\'lucida grande\',tahoma,\'bitstream vera sans\',helvetica,sans-serif;font-size:12px;color:#666;">	       
	 		<p><a href="http://'.YCTOOL_HTTPHOST.'/'.$regurl.'" target="_blank"><img src=http://'.YCTOOL_HTTPHOST.'/'.$face.'.jpg width="75" height="80" border="0" style="padding:2px; border:1px solid #cccccc;" /></a><br>
			<a href="http://'.YCTOOL_HTTPHOST.'/'.$regurl.'" target="_blank">'.$fromname.'</a><br /><br />

			如果你已经拥有'.YCTOOL_HTTPHOST.'账户，<br /><br />请点击以下链接：<br /><br />
			<a href="http://'.YCTOOL_HTTPHOST.'/user.php?uid='.$userid.'" target="_blank">
			http://'.YCTOOL_HTTPHOST.'/user.php?uid='.$userid.'</a>

	 		</p>';

	$userPath = 'userdata/'.func::getFilePath($userid);
	$allPath = $userPath . 'myfriend.php';
	if (file_exists($allPath))
	{
	    require_once($allPath);
	    if(count($arr_all_friend))
	    {
		$detailhtml .= '<br>我已有'.count($arr_all_friend).'位好友加入了<br><p>';
		foreach ($arr_all_friend as $key => $value)
		{
		    //得到该用户的头像路径
		    $userpath_img = 'userdata/' . func::getFilePath($value['friendid'], 'config') . 'face.jpg';
    
		    if (!file_exists($userpath_img))
		    {
			$userpath_img = "image/default/nopic50.gif";//缺省的头像路径
		    }
		    $detailhtml .='<DIV style="float:left; margin:3px;"><IMG src="http://'.YCTOOL_HTTPHOST.'/'.$userpath_img.'" height=50 width=50
		    style="padding:2px; border:1px solid #cccccc;"><br>'.$value['username'].'</DIV>';
		}	    
	    }
	}
	$detailhtml .='</p>
			  <p>&nbsp;</p>
			 </td>
			<td width="447" valign="top" align="left" style="padding:20px 20px 20px 0; font-family:\'lucida grande\',tahoma,\'bitstream vera sans\',helvetica,sans-serif;line-height:150%;color:#000;font-size:12px;">邀请附言：<br />
			
				<font color=red>'.$detail.'</font><br /><br />
				本邀请由'.$fromname.'发出  The invitation is sent by '.$fromname.'<br />
				<a href="http://'.YCTOOL_HTTPHOST.'/'.$regurl.'" target=_blank>http://'.YCTOOL_HTTPHOST.'/'.$regurl.' </a><br /><br />
				'.$now1.'<br />
			</td>
		</tr>
	</table>
</td></tr></table>
</BODY></HTML>';

            $detailhtml = '<META http-equiv=Content-Type content="text/html; charset='.Email_CHARSET.'"></HEAD>
                '.$detail.'<br /> <br /> 
                本邀请由'.$fromname.'发出<br />
                The invitation was sent by '.$fromname.'<br /> 
                ';
                        require_once(DIR_COMM . 'sendmail.php');
            $isMailrs = explode(',', $isMail);
            foreach ($isMailrs as $v)
            {
                $isOk = SendMail($v, $fromname.' 邀请您加入童心网', $detailhtml);
            }
/*
	    if($isOk)
	    {
		$isMail = '下列邮箱地址发送成功:<br /> '.$isMail;
	    }
	    else
	    {
		func::showMsg($isMail.'输入邮箱错误或者网络延迟，<a href="javascript:location.reload();">点击这里,重新发送</a> ，<br /><br />点击下面确定返回。');
            }
*/
	    if (!empty($erroremail))
	    {
		    $isMail .= ' <br />'.'下列邮箱地址格式有问题:<br />'.$erroremail;
	    }
    }
    if($isMail)
    {
	$text = '对您的好友已经发出邀请，您可以返回发送给其他好友'; 
    }
    else
    {
	$text = '没有符合格式的邮箱，点击下面确定返回重新提交'; 
    }
    break;
case 'showdata'://详细资料页面
    $menu = 0;//导航: 0 为首页。
    $uidpathconfig = 'userdata/'.func::getFilePath($uid).'config/';
    $rs = $user->getUserBasicMember($uid);
    $rs = $rs[0];

    $tempbirth = $rs['birth_year'];
    if($rs['birth_year'] != '90后' && $rs['birth_year'] != '80后' && $rs['birth_year'] != '70后')

    {
	$tempbirth .= '年';
    }
    $tempbirth .= $rs['birth_month'] .'月'. $rs['birth_day'] .'日';
				

    $htmlvalue0[0] = $rs['username'];
    $htmlvalue[0] = $rs['sex'];

    $htmlvalue[1] = $tempbirth;
    $htmlvalue[2] = $rs['email'];
    $htmlvalue[3] = $rs['tel'];
    $htmlvalue[4] = $rs['address'];

    $htmlvalue[5] = $rs['field1'];
    $htmlvalue[6] = $rs['field2'];
    $htmlvalue[7] = $rs['field3'];
    $htmlvalue[8] = $rs['field4'];
    $htmlvalue[9] = $rs['field5'];
    $htmlvalue[10] = $rs['field6'];
    $htmlvalue[11] = $rs['field7'];
    $htmlvalue[12] = $rs['field8'];
    $htmlvalue[13] = $rs['field9'];


    include_once('config2.php');

    //是否好友
    $uidpath = 'userdata/'.func::getFilePath($uid);   
    $arr_all_friend = array();
    if (file_exists($uidpath.'myfriend.php'))
    {
	require($uidpath.'myfriend.php');
    }
    $friendid = array();
    if(array_unique($arr_all_friend))
    {
	foreach ($arr_all_friend as $item)
	{
	    $friendid[] = $item['friendid'];
	}
    }

    //uid 隐私设置中 可能出现的网络
    $rsorg = db::getCol( DB_TABLEPRE . 'user_org', 'orgid',  "userid = $uid AND active = 1");
    $rsorg = @implode(',', $rsorg);
    $rsporg = db::getAll( DB_TABLEPRE . 'user_privacy_org', 'orgid,userid,type',  "orgid IN ($rsorg) AND userid = $uid");
    if(!$rsporg)
    {
	$rsporg = array();
    }

    //获取 userid 在uid 隐私中 可能出现的网络
    foreach($rsporg as $k)
    {
        $rsorgT[] = $k['orgid'];
    }
    $rsorg = @implode(',', $rsorgT);
    $rsorg = db::getCol( DB_TABLEPRE . 'user_org', 'orgid',  "orgid IN ($rsorg) AND userid = $userid AND active = 1");
    if(!$rsorg)
    {
	$rsorg = array();
    }

    //隐私
    $rsprivacy = db::getAll( DB_TABLEPRE . 'user_privacy', 'pinfo,type',  "userid = $uid ");

    foreach($htmltype as $key => $v)
    {
	$udata[$key]['name'] = $htmltype[$key];
	$udata[$key]['title'] = $htmlvalue[$key];
    }


    if($rsprivacy)
    {
    	foreach($rsprivacy as $key => $v)
	{
	    $type = $v['type'];
	    $udata[$type]['name'] = $htmltype[$type];
	    if($v['pinfo'] == 0)//0所有人，1朋友，2我，3没有人。
	    {
                $udata[$type]['title'] = $htmlvalue[$type];
	    }
	    elseif($v['pinfo'] == 2 && $uid == $userid)
	    {
		$udata[$type]['title'] = $htmlvalue[$type];
	    }
	    elseif($v['pinfo'] == 1)
	    {
		if($uid == $userid)
		{
                    $udata[$type]['title'] = $htmlvalue[$type];		 
		}
		else
		{
		    if(in_array($userid, $friendid))
                    {
                        $udata[$type]['title'] = $htmlvalue[$type];
		    }
		    else
                    {
                        if($rsporg)
                        {
                            $typeisexists = 0;
                            foreach($rsporg as $value)
                            {
                                if($value['type'] == $type)
                                {
                                    if(in_array($value['orgid'], $rsorg))
                                    {
                                        $typeisexists = 1;
                                        $udata[$type]['title'] = $htmlvalue[$type];
                                    }
                                }
                            }

                            if(!$typeisexists)
                            {
                                $udata[$type]['title'] = '保密';                        
                            }
                        }
                        else
                        {
                            $udata[$type]['title'] = '保密';
                        }

			if(!$udata[$type]['title'])
                        {
                            $udata[$type]['title'] = '保密';                        
                        }
		    }
		}
	    }
	    else
	    {
		$udata[$type]['title'] = '保密';	
            }
          //echo $udata[$type]['title'];
	  //echo '<hr>';
	}
    }
//exit;
    //$rs = $udata;

    //$rslist = implode(',',array_unique($rslist));

    //$rslist = db::getCol( DB_TABLEPRE . 'user_org', 'userid',  "orgid IN($rslist)");

//print_r($rslist);
//0">所有人可见 "1">朋友和我可见 2">只有我可见 "3">没有人可见
//$userid 是否 $uid 的;

    break;

default:;
    $menu = 0;//导航: 0 为首页。
    $nowtime = date('Y-m-d H:i:s',time());
    //$permun = isset($_GET['permun']) ? $_GET['permun'] : 10;

  
    $page = $_GET['page'];
    unset($_GET['page']);
 
    if (!is_numeric($page) || $page < 1)		 
    {
	$page = 1;
    }
	$perpage_act = $perpage_don = $perpage = 6;
	$active = 2;
 	$count_don = db::getOne('sns_web_doneeinfo', "COUNT(*)", "need > getneed AND active = '$active' ORDER BY acttime desc");
 	$count_act = db::getOne('sns_web_activity', 'COUNT(*)'," endtime > '$nowtime' AND active = '$active' ORDER BY acttime desc");
 
        $last_don = $count_don - $page * $perpage + $perpage;
	if($last_don < 0)
	{
	    $last_don = 0;
	}
        if($last_don >= 6)
	{
	    $perpage_act = 6;
	}
	else
	{
	    $perpage_act = 2*6 - $last_don;
	}

        $last_act = $count_act - $page * $perpage + $perpage;
	if($last_act < 0)
	{
	    $last_act = 0;
	}
        if($last_act >= 6)
	{
	    $perpage_don = 6;
	}
	else
	{
	    $perpage_don = 2*6 - $last_act;
        }
         $tmpp_act = intval($count_act/6) + 1 ;
         $tmpp_don = intval($count_don/6) + 1 ;
        //echo $tmpp_act.'/'.$tmpp_don.'<br>';
        if ($page > $tmpp_act && $tmpp_don > $tmpp_act)
        {

            $pre_act = $count_act - ($page - 2) * 6;
            $pre_don = 12 - $pre_act;
           // echo $pre_don.'<br>';
            $startr = ($page - 2) * 6 + $pre_don ; 
        }         
        else if ($page > $tmpp_don && $tmpp_don < $tmpp_act)
        {
 
            $pre_don= $count_don - ($page - 2) * 12/2;
            $pre_act = 12 - $pre_don;
            //echo $pre_act;
            $startr = ($page - 2) * 12/2 + $pre_act ;
        }
        else
        {
            $startr = ($page - 1) * $perpage ;
        }
  
	$news_don = db::getAll('sns_web_doneeinfo','*'," need > getneed AND active = '$active' ORDER BY acttime DESC LIMIT  $startr, $perpage_don" );
	if (!$news_don)
	{
	    $news_don = array();
	}

	$news_act = db::getAll('sns_web_activity','*'," endtime > '$nowtime' AND active = '$active' ORDER BY acttime DESC LIMIT  $startr,$perpage_act" );
	if (!$news_act)
	{
	    $news_act = array();
	}
	$c_total = $count_don + $count_act;
	$pagestr = func::pageStr($c_total, $page, 12, "?action=&uid=$uid"); 
    }
if($action == 'act' )
{
    (!$uid && !$userid) && func::alertMsg('该连接需要登录 ');
    $preview = isset($_GET['preview']) ? $_GET['preview'] : 'index';
    if($uid && $uid != $userid)
    {
	$uidpath = 'userdata/'.func::getFilePath($uid);
	$uidpathconfig = $uidpath.'config/';

	$arr_all_friend = array();
	if (file_exists($userpathusr.'myfriend.php'))
	{
	    require($userpathusr.'myfriend.php');
	}
	$friendid = array();
	if(array_unique($arr_all_friend))
	{
	    foreach ($arr_all_friend as $item)
	    {
		$friendid[] = $item['friendid'];
	    }
	}
	if(!in_array($uid, $friendid))
	{
	    $actaddfriend = 1;
	}

	$arr_all_friend = array();
	if (file_exists($uidpath.'myfriend.php'))
	{
	    require($uidpath.'myfriend.php');
	}
	$friendid = array();
	if(array_unique($arr_all_friend))
	{
	    foreach ($arr_all_friend as $item)
	    {
		$friendid[] = $item['friendid'];
	    }
	}
	if(in_array($userid, $friendid))
	{
	    $preview = 'friend'; 
	}
	else
	{
	    $preview = 'guest';
	}
	$rsUserInfo = $user->getUserInfoById($uid);
	$uname = $rsUserInfo['username'];
    }
    else
    {
	$uidpath = 'userdata/'.func::getFilePath($userid);
	$uidpathconfig = $uidpath.'config/';   
	$arr_all_friend = array();
	if (file_exists($uidpath.'myfriend.php'))
	{
	    require($uidpath.'myfriend.php');
	}
	$friendid = array();
	if(array_unique($arr_all_friend))
	{
	    foreach ($arr_all_friend as $item)
	    {
		$friendid[] = $item['friendid'];
	    }
	}
	$uname = $username;
    }

    !$uid && $uid = $userid;
    //require_once($uidpathconfig.'privacy.php');
    //func::stripslashesArray($variable);

    //$array2 = array("1003");  黑名单朋友
    //$friendid = array_diff($friendid, $array2);
    
    $variableprivacy[$uid]['myhome'] = 1;

    if($preview == 'guest')
    {
	//$comma_separated = $uid;
	if($variableprivacy[$uid]['myhome'] == 1)
	{
	    $myhome =  1;
	}
    }
    elseif($preview == 'friend')
    {
	//$comma_separated = $uid;
	if($variableprivacy[$uid]['myhome'] == 0 || $variableprivacy[$uid]['myhome'] == 1)
	{
	    $myhome =  1;
	}
    }
    else
    {
	//$comma_separated = implode(",", $friendid); 
	$myhome =  1;
    }
    $comma_separated = implode(",", $friendid); 
    
    //好友动态
    if($myhome == 1)
    {


        $page = $_GET['page'];
        if (!is_numeric($page) || $page < 1)		 
        {
            $page = 1;
        }
	!$comma_separated && $comma_separated = 1;
	require(DIR_MODEL . "msg.func.php");
	if($preview == 'index') { $whereSql = 'a.friendid <> '.$userid.' AND a.userid <> '. $userid; }else{ $whereSql = 'a.userid <> '. $uid; }
	$permun = isset($_GET['permun']) ? $_GET['permun'] : 20;

        $whereSql .= " AND ( ";
        foreach ($arr_all_friend as $v)
        {
            //mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
            $temp = explode(" ", $v['time']);
	    $dateArray = explode("-", $temp[0]);	    
	    //$dateArray[0] . '年' . $dateArray[1] . '月' .  $dateArray[2] . '日 '
	    $timeArray = explode(":", $temp[1]);	    
            //$timeArray[0] . '小时' . $timeArray[1] . '分' .  $timeArray[2] . '秒 '
           $addfriendtime = mktime ( $timeArray[0] , $timeArray[1] ,$timeArray[2], $dateArray[1], $dateArray[2], $dateArray[0] );
            //$v['friendid']
            $addfriendid = $v['friendid'];
            $whereSql .= "  ( ( a.userid = $addfriendid OR a.friendid = $addfriendid)
                               AND $addfriendtime < a.addtime ) OR ";

        
        }
        $whereSql .= " 1 <> 1 ) ";

        //echo $whereSql;

	$rs = msg::getMsgAction($comma_separated, $whereSql, $permun, $page);
//exit;
	$count_act = db::getOne(DB_TABLEPRE . 'msg_action a LEFT JOIN sns_user_basic b ON a.userid = b.userid', 'COUNT(*)', 
	    '(a.userid IN('.$comma_separated.') OR a.friendid IN('.$comma_separated.')) AND '.$whereSql);

	$pagestr = func::pageStr($count_act, $page, $permun, "user.php?action=act&uid=$uid"); 

	if($rs)
	{
	    foreach ($rs as $item)
	    {
		$userFriendid[] = $item['userid'];
		$userFriendid[] = $item['friendid'];
	    }
	    $userFriendid = array_unique($userFriendid);
	    $userFriendid = implode(",", $userFriendid);
	    $userFriendRs = $user->getUserStr($userFriendid);
	    unset($userFriendid);

	    while (list($key, $value) = each($userFriendRs))
	    {
		$arrUser[$value['userid']]['userid'] = $value['userid'];
		$arrUser[$value['userid']]['username'] = $value['username'];
	    }
	    unset($userFriendRs);
	}
    }
    $visitorid = explode(",", $comma_separated);
    if (file_exists($uidpath . 'visitor.php'))
    {
	require_once($uidpath . 'visitor.php');
    }
    else
    {
	$arr_all_visitor = array();
    }
    if(array_unique($arr_all_visitor))
    {
	if($arr_all_visitor)
	{
	    foreach ($arr_all_visitor as $item)
	    {
		$visitorid[] = $item[friendid];
	    }
	}
    }
    $visitorid = @implode(",", $visitorid);
    //是否在线
    $ArrUserid = $user->onLineStr($visitorid);
    !$ArrUserid && $ArrUserid = array();
    $rsuser = $user->getUserBasicMember($uid);
    

    //添加访客
    if($uid && $userid && $uid != $userid)
    {
	/**
	 *  将自己访问的一个好友信息保存到好友的文件中
	 *  @param userid      用户编号
	 *  @param visitor     访问者编号
	 *  @return int 1:操作成功;0:操作失败
	 */
	function addVisitorI($visitorid, $visitorname, $uidpath, $arr_all_visitor)
	{
		$lasttime = strtotime($arr_all_visitor[$visitorid]["time"]);
		$lasttime = time() - $lasttime;
		if($lasttime > 300)
		{
			if(count($arr_all_visitor) > 0)
			{
			$arr_all_visitorT = array();
				$i==0;
				foreach($arr_all_visitor as $key => $value)
				{
					if($i < 200)
					{
						$arr_all_visitorT[$value['friendid']]['friendid'] = $value['friendid'];
						$arr_all_visitorT[$value['friendid']]['time'] = $value['time'];
						$arr_all_visitorT[$value['friendid']]['username'] = $value['username'];
					}
				$i++;
				}
			}
			
			$arr_all_visitorT[$visitorid]["friendid"] = $visitorid;
			$arr_all_visitorT[$visitorid]["time"] = date('Y-m-d H:i:s');
			$arr_all_visitorT[$visitorid]["username"] = $visitorname;
			func::operateFile('arr_all_visitor', $arr_all_visitorT, 'visitor.php', "php", 2, $uidpath);
		}
	}

	/**
	 *  将一个访问自己的好友信息保存到自己的文件中
	 *  @param userid      用户编号
	 *  @param $friendid   访问者编号
	 *  @return int 1:操作成功;0:操作失败 
	 */
	function addVisitedFileI($uid, $uname, $userpathusr)
	{
		$arr_all_visited = array();
		if (file_exists($userpathusr.'visited.php'))
		{
			require_once($userpathusr.'visited.php');
			
		}
		$lasttime = strtotime($arr_all_visited[$uid]["time"]);
		$lasttime = time() - $lasttime;
		if($lasttime > 300)
		{
			if(count($arr_all_visited) > 0)
			{
				$i==0;
				foreach($arr_all_visited as $key => $value)
				{
					if($i < 200)
					{
						$arr_all_visitedT[$value['friendid']]['friendid'] = $value['friendid'];
						$arr_all_visitedT[$value['friendid']]['time'] = $value['time'];
						$arr_all_visitedT[$value['friendid']]['username'] = $value['username'];
					}
				$i++;
				}
			}
			$arr_all_visitedT[$uid]["friendid"] = $uid;
			$arr_all_visitedT[$uid]["time"] = date('Y-m-d H:i:s');
			$arr_all_visitedT[$uid]["username"] = $uname;
			func::operateFile('arr_all_visited', $arr_all_visitedT, 'visited.php', "php", 2, $userpathusr);
			unset($arr_all_visitedT);
		}
	}
	addVisitorI($userid, $username, $uidpath, $arr_all_visitor);
	addVisitedFileI($uid, $uname, $userpathusr);
    }

}
require_once DIR_COMM.'template.func.php';
require_once tpl('user'.$action.'.html', $tpldir);
exit;
?>
